package com.tc.utils;

import com.tc.dto.AppBean;
import com.tc.dto.Login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class SetWeChatServer {
    @Autowired
    private AppBean appBean;

    //向微信服务器获取openid与sessionKey
    public String getOpenIdAndSessionKey(Login login){
        String url="https://api.weixin.qq.com/sns/jscode2session?"
                +"appid="+appBean.getAppId()
                +"&secret="+appBean.getSecret()
                +"&js_code="+login.getCode()
                +"&grant_type=authorization_code";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(url,String.class);
    }

}
